import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:star_author/config/ui_constant.dart';
import 'package:star_author/widgets/base_widget/line/h_line.dart';
import 'package:star_author/widgets/base_widget/line/v_line.dart';
import 'package:star_author/widgets/empty_view/v_empty_view.dart';

///author：liu

class CustomAlertDialog extends Dialog {
  final String? title;
  final String content;
  final bool isShowCancelButton;
  final VoidCallback? confirmCallback;
  final VoidCallback? cancelCallback;
  final String? confirmBtnStr;
  final String? cancelBtnStr;
  final TextAlign? textAlign;

  CustomAlertDialog({
    this.title,
    this.content = '副标题',
    this.isShowCancelButton = false,
    this.confirmCallback,
    this.cancelCallback,
    this.confirmBtnStr = "确认",
    this.cancelBtnStr = "取消",
    this.textAlign = TextAlign.center,
  });

  @override
  Widget build(BuildContext context) {
    List<Widget> buttonList = [];
    if (isShowCancelButton) {
      buttonList.add(
        Expanded(
          flex: 1,
          child: GestureDetector(
            onTap: () {
              Navigator.pop(context);
              cancelCallback?.call();
            },
            behavior: HitTestBehavior.opaque,
            child: Container(
              width: 65.w,
              height: 44.w,
              alignment: Alignment.center,
              child: Text(
                cancelBtnStr!,
                style: TextStyle(
                  color: UIConstant.color99,
                  fontSize: 16.sp,
                ),
              ),
            ),
          ),
        ),
      );
      buttonList.add(
        VLine(44.w),
      );
    }
    buttonList.add(
      Expanded(
        flex: 1,
        child: GestureDetector(
          onTap: () {
            Navigator.pop(context);
            confirmCallback?.call();
          },
          behavior: HitTestBehavior.opaque,
          child: Container(
            alignment: Alignment.center,
            child: Text(
              confirmBtnStr!,
              style: TextStyle(
                color: UIConstant.colorEBA07,
                fontSize: 16.sp,
                fontWeight: FontWeight.w500,
              ),
            ),
          ),
        ),
      ),
    );

    return Center(
      child: Container(
        width: 280.w,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(
            Radius.circular(10.w),
          ),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: [
            VEmptyView(4.w),
            if (title != null) ...[
              VEmptyView(14.w),
              Text(
                title!,
                style: TextStyle(
                  color: UIConstant.color33,
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ],
            VEmptyView(20.w),
            Container(
              margin: EdgeInsets.only(
                bottom: 24.w,
                left: 23.w,
                right: 23.w,
              ),
              child: Text(
                content,
                textAlign: textAlign,
                style: TextStyle(
                  color: UIConstant.color33,
                  fontSize: 16.sp,
                ),
                maxLines: 18,
                overflow: TextOverflow.ellipsis,
              ),
            ),
            HLine(270.w),
            SizedBox(
              width: 270.w,
              height: 44.w,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: buttonList,
              ),
            )
          ],
        ),
      ),
    );
  }
}
